package cn.jiyun.service.impl;


import cn.jiyun.mapper.ProjectMapper;
import cn.jiyun.page.PageResult;
import cn.jiyun.page.QueryPageBean;
import cn.jiyun.pojo.Project;
import cn.jiyun.service.ProjectService;
import com.alibaba.druid.sql.PagerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public int add(Project project) {
        project.setUpdatetime(new Date());
      return   projectMapper.add(project);
    }

    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        List<Project> list = projectMapper.findAll((queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize(), queryPageBean.getPageSize(),queryPageBean.getQueryString());
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        Long pageSize =projectMapper.getCount();
        pageResult.setTotal(pageSize);
        return new PageResult(pageResult.getTotal(),pageResult.getRows());
    }

    @Override
    public int update(Project project) {
        project.setUpdatetime(new Date());
        return projectMapper.update(project);
    }

    @Override
    public int delete(Integer pid) {
        return projectMapper.delete(pid);
    }

    @Override
    public Project findById(Integer pid) {
        Project byId = projectMapper.findById(pid);
        return byId;
    }

    @Override
    public List<Project> findName() {
        return projectMapper.findName();
    }
}
